package cn.stylefeng.guns.sys.modular.vote.controller;


import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.vote.entity.VoteInfo;
import cn.stylefeng.guns.sys.modular.vote.mapper.VoteInfoMapper;
import cn.stylefeng.guns.sys.modular.vote.model.params.VoteInfoParam;
import cn.stylefeng.guns.sys.modular.vote.service.VoteInfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 公示表控制器
 *
 * @author WangZhen
 * @Date 2021-01-28 15:40:11
 */
@Controller
@RequestMapping("/voteInfo")
public class VoteInfoController extends BaseController {

    private String PREFIX = "/modular/vote/vote";

    @Autowired
    private VoteInfoService voteInfoService;

    /**
     * 跳转到主页面
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/VoteInfo.html";
    }

    /**
     * 新增页面
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/VoteInfo_add.html";
    }

    /**
     * 编辑页面
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/VoteInfo_edit.html";
    }


    /**
     * 跳转到发起投票页面
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/vote")
    public String vote() {
        return PREFIX + "/VoteApprove.html";
    }


    /**
     * 跳转到投票情况页面
     *
     * @author WangZhen
     * @Date 2021-02-07
     */
    @RequestMapping("/showVoteInfo")
    public String showVoteInfo() {
        return PREFIX + "/ShowVoteInfo.html";
    }


    /**
     * 编辑接口
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/showVoteInfoById")
    @ResponseBody
    public ResponseData showVoteInfoById(Integer param) {
        return ResponseData.success(this.voteInfoService.showVoteInfoById(param));
    }


    /**
     * 新增接口
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(@RequestParam Map<String, Object> param) {
//        param.put("_session_user", LoginContextHolder.getContext().getUser().getId());
//        VoteInfoMapper.insertProjectPublicity(param);
//        Object id = param.get("id");
//        param.put("VoteId", id);
//        List houseList = JSON.parseArray((String) param.get("houseList"));
//        for (Object obj : houseList) {
//            param.put("_thisHouseId", obj);
//            //插入人员
//            VoteInfoMapper.insertPublicityAndHouse(param);
//        }
//
//        boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
//        if (isWindows) {
//            TRUE_PATH = uploadPathWindows;
//        } else {
//            TRUE_PATH = uploadPathLinux;
//        }
//
//        try {
//            File xmtp = new File(TRUE_PATH + id.toString() + XMTP);
//            PrintStream ps = new PrintStream(new FileOutputStream(xmtp));
//            File jytp = new File(TRUE_PATH + id.toString() + JYTP);
//            PrintStream ps_jy = new PrintStream(new FileOutputStream(jytp));
//            if (param.get("fileList") != null) {
//                ps.println(param.get("fileList"));
//            }
//            if (param.get("file_list_jytp") != null) {
//                ps_jy.println(param.get("file_list_jytp"));
//            }
//        } catch (FileNotFoundException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        } finally {
//            System.out.println("file ok: " + id);
//        }
        return ResponseData.success();
    }


    /**
     * 编辑接口
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(VoteInfoParam VoteInfoParam) {
        this.voteInfoService.update(VoteInfoParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(VoteInfoParam VoteInfoParam) {
        this.voteInfoService.delete(VoteInfoParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(VoteInfoParam VoteInfoParam) {
        VoteInfo detail = this.voteInfoService.getById(VoteInfoParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author WangZhen
     * @Date 2021-01-28
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(VoteInfoParam VoteInfoParam) {
        return this.voteInfoService.findPageBySpec(VoteInfoParam);
    }


    /**
     * 查看详情接口
     *
     * @author WangZhen
     * @Date 2021-02-04
     */
    @RequestMapping("/startVote")
    @ResponseBody
    public ResponseData startVote(@RequestParam Map<String, Object> param) {
        this.voteInfoService.startVoteService(param);
        return ResponseData.success();
    }

}


